home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / lisp / eulisp / mpfeel.lha / MPFeel / system_p.h < prev    next >
C/C++ Source or Header  |  1992-10-06  |  6KB  |  233 lines

  1. /* ******************************************************************** */
  2. /* system.h          Copyright (C) Codemist and University of Bath 1989 */
  3. /*                                                                      */
  4. /* Environment specific code                                           */
  5. /* ******************************************************************** */
  6.  
  7. /*
  8.  * $Id: system_p.h,v 1.3 1992/01/29 13:49:32 pab Exp $
  9.  *
  10.  * $Log: system_p.h,v $
  11.  * Revision 1.3  1992/01/29  13:49:32  pab
  12.  * sysV fixes
  13.  *
  14.  * Revision 1.2  1991/09/11  12:07:47  pab
  15.  * 11/9/91 First Alpha release of modified system
  16.  *
  17.  * Revision 1.1  1991/08/12  16:50:06  pab
  18.  * Initial revision
  19.  *
  20.  * Revision 1.7  1991/05/16  11:31:20  pab
  21.  * 'C' garbage collector additions
  22.  *
  23.  * Revision 1.5  1991/02/28  13:53:19  kjp
  24.  * Fixed fopen/close macros in sysv - added GC state codes.
  25.  *
  26.  * Revision 1.4  1991/02/13  18:26:05  kjp
  27.  * Pass.
  28.  *
  29.  */
  30.  
  31. /*
  32.  * System specific prototypes...
  33.  *
  34.  * (see '.c' for details)
  35.  */
  36.  
  37. #ifndef SYSTEM_P_H
  38.  
  39. #define SYSTEM_P_H
  40.  
  41. /*
  42.  * Interfaces...
  43.  */
  44.  
  45. extern int system_running_processors;
  46. #define RUNNING_PROCESSORS() (system_running_processors)
  47.  
  48. /* ******************************************************************** */
  49. /*                             System V                                 */
  50. /* ******************************************************************** */
  51.  
  52. #ifdef MACHINE_SYSTEMV
  53.  
  54. extern int system_scheduler_number;
  55.  
  56. #define system_fopen(f,m) (fopen(f,m))
  57. #define system_fclose(f)  (fclose(f))
  58.  
  59. extern int system_read(int,char*,int);
  60.  
  61. extern char *system_malloc(int);
  62. extern char *system_static_malloc(int);
  63. /*
  64. #define system_allocate_semaphore(addr) (*(addr)=semget(IPC_PRIVATE,1,NULL))
  65. #define system_initialise_semaphore(addr) semctl(*(addr),0,SETVAL,1)
  66. #define system_open_semaphore(addr) semop(*(addr),&system_sem_handler,1)
  67. #define system_close_semaphore(addr) semctl(*(addr),0,SETVAL,1)
  68. */
  69.  
  70. extern void system_allocate_semaphore(SystemSemaphore *);
  71. extern void system_initialise_semaphore(SystemSemaphore *);
  72. extern void system_open_semaphore(LispObject *,SystemSemaphore *);
  73. extern void system_close_semaphore(SystemSemaphore *);
  74. extern int system_maybe_open_semaphore(LispObject *, SystemSemaphore *);
  75.  
  76. extern LispObject system_thread_rig(LispObject*,LispObject);
  77. extern LispObject system_thread_start(LispObject);
  78. extern LispObject system_thread_call(LispObject);
  79. extern LispObject system_thread_suspend(void);
  80. extern LispObject system_thread_reschedule(void);
  81. extern void system_thread_abort(void);
  82.  
  83. #define GC_sync_test() \
  84.           (SYSTEM_GLOBAL_VALUE(GC_state) == GC_SINKING \
  85.             ? ((void) garbage_collect(stacktop),TRUE) \
  86.         : FALSE)
  87.  
  88. #endif
  89.  
  90. /* ******************************************************************** */
  91. /*                            Any Machine                               */
  92. /* ******************************************************************** */
  93.  
  94. #ifdef MACHINE_ANY
  95.  
  96. #ifndef PROCESSORS
  97. #define PROCESSORS (1)
  98. #endif
  99.  
  100. #define system_fopen(f,m) (fopen(f,m))
  101. #define system_fclose(f)  (fclose(f))
  102.  
  103. #define system_read(a,b,c) (read(a,b,c))
  104.  
  105. extern char *system_malloc(int);
  106. #ifdef CGC
  107. #define  system_malloc(n) gc_malloc(n)
  108. #define system_static_malloc(n) gc_malloc(n)
  109. #else
  110. extern char *system_static_malloc(int);
  111. #endif
  112.  
  113. #define system_allocate_semaphore(addr) IGNORE(*addr)
  114. #define system_initialise_semaphore(addr)
  115. #define system_open_semaphore(x,addr)
  116. #define system_close_semaphore(addr)
  117. #define system_maybe_open_semaphore(x,addr) (1)
  118.  
  119. extern int system_scheduler_number;
  120.  
  121. /* Place where 'system_thread' calls would be */
  122.  
  123. #define GC_sync_test()
  124.  
  125. #endif
  126.  
  127. /* ******************************************************************** */
  128. /*                               BSD                                    */
  129. /* ******************************************************************** */
  130.  
  131. #ifdef MACHINE_BSD
  132.  
  133. extern int system_scheduler_number;
  134.  
  135. #define system_fopen(f,m) (fopen(f,m))
  136. #define system_fclose(f)  (fclose(f))
  137.  
  138. #define system_read(a,b,c) (read(a,b,c))
  139.  
  140. extern char *system_malloc(int);
  141. extern char *system_static_malloc(int);
  142.  
  143. #define system_allocate_semaphore(addr) (*(addr)=1)
  144. #define system_initialise_semaphore(addr) (*(addr)=1)
  145. #define system_open_semaphore(x,addr) \
  146.           { \
  147.         if (*(addr)!=1){ \
  148.           fprintf(stderr,"Unexpected value of semaphore"); \
  149.          \
  150.         } \
  151.         *(addr) = 0; \
  152.       }
  153. #define system_close_semaphore(addr) (*(addr)=1)
  154. #define system_maybe_open_semaphore(x,addr) (*(addr) == 1 ? *addr = 0,1 : 0)
  155.  
  156. extern LispObject system_thread_rig(LispObject*,LispObject);
  157. extern LispObject system_thread_start(LispObject);
  158. extern LispObject system_thread_call(LispObject);
  159. extern LispObject system_thread_suspend(void);
  160. extern LispObject system_thread_reschedule(void);
  161. extern void system_thread_abort(void);
  162.  
  163. #define GC_sync_test()
  164.  
  165. #endif
  166.  
  167. /* Thread system prototypes... */
  168.  
  169. #include "defs.h"
  170. extern SYSTEM_GLOBAL_ARRAY1(LispObject,system_scheduler_threads,MAX_PROCESSORS);
  171.  
  172. /* Initialisation prototypes... */
  173.  
  174. extern void runtime_initialise_system(void);
  175. extern void system_initialise_scheduler(void);
  176. extern void system_lisp_exit(int);
  177.  
  178. #define THREAD_LIMBO (0)
  179. #define THREAD_READY (1)
  180. #define THREAD_RUNNING (2)
  181. #define THREAD_RETURNED (3)
  182. #define THREAD_ABORTED (4)
  183.  
  184. #define GC_SINKING    (0)
  185. #define GC_REGISTERED (1)
  186. #define GC_MARKED     (2)
  187. #define GC_DONE       (3)
  188.  
  189. extern SYSTEM_GLOBAL(int,GC_state);
  190.  
  191. #ifndef SYSTEM_MAX_SHARED_SIZE
  192. #define SYSTEM_MAX_SHARED_SIZE (4*1024*1024)
  193. #endif
  194.  
  195. #ifdef WITH_PROFILING
  196.  
  197. #include <sys/time.h>
  198.  
  199. #define PROFILE_RUNNING  ('R')
  200. #define PROFILE_IDLE     ('I')
  201. #define PROFILE_GC_START ('G')
  202. #define PROFILE_GC_END   ('E')
  203. #define PROFILE_BLOCKED  ('B')
  204.  
  205. #define PROFILE(x) x
  206.  
  207. #define DEF_PROFILE_TIMER(name) struct itimerval *name
  208.  
  209. #define INIT_PROFILE_TIMER(name) \
  210.           name \
  211.             = (struct itimerval *) \
  212.                 system_static_malloc(sizeof(struct itimerval)); \
  213.           name->it_interval.tv_sec = 0; \
  214.           name->it_interval.tv_usec = 10; \
  215.           name->it_value.tv_sec = 0; \
  216.           name->it_value.tv_usec = 0; \
  217.           setitimer(ITIMER_REAL,name,NULL); 
  218.  
  219. #define PROFILE_TIME(name) (name->it_value.tv_sec)
  220.  
  221. extern struct itimerval *system_local_timer;
  222.  
  223. #else
  224. #define PROFILE(x)
  225. #define DEF_PROFILE_TIMER(x)
  226. #define INIT_PROFILE_TIMER(x)
  227. #define PROFILE_TIME(x)
  228. #endif
  229.  
  230. #endif SYSTEM_P_H
  231.  
  232.  
  233.